package com.pig.consume.invoker;

import com.pig.common.ClassUtils;
import com.pig.common.RpcContext;
import com.pig.common._enum.ProtocolEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author Administrator
 */
@Slf4j
public class ConsumeFactoryBean<T> implements FactoryBean {
    private String clazz;
    private Class selfClass;
    private ProtocolEnum protocol;

    @Override
    public Object getObject() {
        RpcContext.put(selfClass.getName(), protocol);
        return Invoker.getInstance(selfClass);
    }

    @Override
    public Class<T> getObjectType() {
        return selfClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
        this.selfClass = ClassUtils.forName(clazz);
    }

    public ProtocolEnum getProtocol() {
        return protocol;
    }

    public void setProtocol(ProtocolEnum protocol) {
        this.protocol = protocol;
    }

    public String getClazz() {
        return clazz;
    }
}
